<?php 
class CategoryController extends Controller {
	var $name = "Category";
	var $uses = array('Product', 'Category');
	var $components = array('Utils');
	
	function index($slug=null) {
		$cats = $this->Utils->getCategoryList();
		$catArray = array();
		foreach($cats as $cat) {
			$catArray[] = $cat['Category']['id'];
		}
		
		$this->set('cats', $cats);
		
		$subcat = $this->Category->find('first', 
			array(
				'conditions' => array(
					'Category.slug'  => $slug
				)
			)
		);
		$this->set('currentCat', $subcat);
		$subcats = $this->Utils->getSubCategory($subcat['Category']['id']);
		
		$subcatArray = array();
		foreach($subcats as $subcat) {
			$subcatArray[] = $subcat['Category']['id'];
		}
		
		$this->set('subcats', $subcats);
		$index = rand(0, count($subcatArray));
		$catId = $subcatArray[$index];
		$slug = $subcats[$index]['Category']['slug'];
		$this->set('slug', $slug);
		
		$catId = 1;
		$new = $this->Utils->getNewArrivalsProduct($catId);
		$this->set('new', $new);
		
		$hot = $this->Utils->getHotNewRelease($catId);
		$this->set('hot', $hot);
		
		$best = $this->Utils->getBestSeller($catId);
		$this->set('best', $best);
		
		$recommend = $this->Utils->getRecommendProduct($catId);
		$this->set('recommend', $recommend);
	}
}
?>